import 'package:flutter/material.dart';
import './res/list_data.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
          colorScheme: const ColorScheme(
              primary: Colors.black,
              surfaceVariant: Colors.white,
              secondary: Colors.green,
              background: Colors.white, //整个页面背景色
              error: Colors.red,
              brightness: Brightness.light,
              onBackground: Colors.white,
              outlineVariant: Colors.white,
              onError: Colors.yellow,
              onPrimary: Colors.white,
              onSecondary: Colors.white,
              onSurface: Color.fromARGB(255, 233, 233, 240),
              surface: Color.fromARGB(255, 17, 0, 255)) //整个标题栏颜色
          // primarySwatch: Colors.blue, // 设置主色调,无效，怎么设都是白色
          ),
      home: Scaffold(
        appBar: AppBar(title: const Text("图标"), centerTitle: true),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({super.key}) {
    print(listData);
  }

  List<Widget> _initListData() {
    // List<Widget> tempList = [];
    // for (var i = 0; i < listData.length; i++) {
    //   tempList.add(ListTile(
    //     leading: Container(
    //         // alignment: Alignment.centerRight,
    //         width: 100,
    //         decoration: const BoxDecoration(color: Colors.amber),
    //         child:
    //             Image.network("${listData[i]["imageUrl"]}", fit: BoxFit.cover)),
    //     title: Text(
    //       "${listData[i]["title"]}",
    //       style: const TextStyle(fontSize: 23, color: Colors.black),
    //     ),
    //     subtitle: Text(
    //       "${listData[i]["author"]}",
    //       style: const TextStyle(
    //           fontSize: 20, color: Color.fromARGB(213, 68, 67, 67)),
    //     ),
    //   ));
    // }
    var tempList = listData.map((value) {
      return ListTile(
        leading: Container(
            // alignment: Alignment.centerRight,
            width: 100,
            decoration: const BoxDecoration(color: Colors.amber),
            child: Image.network("${value["imageUrl"]}", fit: BoxFit.cover)),
        title: Text(
          "${value["title"]}",
          style: const TextStyle(fontSize: 23, color: Colors.black),
        ),
        subtitle: Text(
          "${value["author"]}",
          style: const TextStyle(
              fontSize: 20, color: Color.fromARGB(213, 68, 67, 67)),
        ),
      );
    });
    return tempList.toList();
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: _initListData(),
    );
  }
}
